﻿using Hallenberg.SmartClient.Menu;
using NUnit.Framework;
using System;

namespace Hallenberg.SmartClient.Test.Menu
{
    [TestFixture]
    public class ChildMenuItemsCollectionTest
    {
        [Test]
        public void ShouldAddNewMenuItem()
        {
            ChildMenuItemsCollection menuItemsCollection = new ChildMenuItemsCollection();

            menuItemsCollection.Add(new MenuItem("SomeMenuName", "SomeTitle", "A Tooltip"));

            Assert.That(menuItemsCollection.Count, Is.EqualTo(1));
        }

        [Test]
        public void ShouldThrowArgumentNullException()
        {
            ChildMenuItemsCollection menuItemsCollection = new ChildMenuItemsCollection();

            ArgumentNullException exception = Assert.Throws<ArgumentNullException>(() => menuItemsCollection.Add(null));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.EqualTo("menuItem"));
        }

        [Test]
        public void ShouldBeAbleToRetrieveItemByIndexer()
        {
            MenuItem menuItem = new MenuItem("ItemName", "The Title", "Some Tooltip");
            ChildMenuItemsCollection menuItemsCollection = new ChildMenuItemsCollection();

            menuItemsCollection.Add(menuItem);

            MenuItem retrievedItem = menuItemsCollection[0];

            Assert.That(retrievedItem.MenuItemTitle, Is.EqualTo(menuItem.MenuItemTitle));
            Assert.That(retrievedItem.ToolTip, Is.EqualTo(menuItem.ToolTip));
            Assert.That(retrievedItem.MenuItemName, Is.EqualTo(menuItem.MenuItemName));
        }

        [Test]
        public void ShouldThrowIndexOfOutRangeException()
        {
            ChildMenuItemsCollection menuItemsCollection = new ChildMenuItemsCollection();

            MenuItem lowerItem = null;
            MenuItem upperItem = null;

            ArgumentOutOfRangeException lowerException = Assert.Throws<ArgumentOutOfRangeException>(() => 
                lowerItem = menuItemsCollection[int.MinValue]);

            ArgumentOutOfRangeException upperException = Assert.Throws<ArgumentOutOfRangeException>(() => 
                upperItem = menuItemsCollection[int.MaxValue]);

            Assert.That(lowerException, Is.Not.Null);
            Assert.That(lowerException.ParamName, Is.EqualTo("index"));
            Assert.That(upperException, Is.Not.Null);
            Assert.That(upperException.ParamName, Is.EqualTo("index"));
        }

        [Test]
        public void ShouldBeAbleToRetrieveIndexOfMenuItem()
        {
        }
    }
}
